package com.example.pipibee.service.imp;

import com.example.pipibee.dao.repository.MrRepository;
import com.example.pipibee.pojo.param.UpLoadParam;
import com.example.pipibee.service.MrService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


@Slf4j
@Service
public class MrServiceImp implements MrService {

    @Autowired
    MrRepository mrRepository;

    @Override
    public void upload(MultipartFile file) {
        log.debug("开始执行【文件上传】的数据访问，参数：{}", file);

        try {

            String filename = file.getOriginalFilename();
            Long filesize = file.getSize() / 1024;
            String filetype = file.getContentType();
            byte[] bytes = file.getBytes();

            UpLoadParam upLoadParam = new UpLoadParam(filename, filesize, filetype, bytes);
            mrRepository.upload(upLoadParam);

        } catch (IOException e) {
            e.printStackTrace();
        }


    }

}
